package com.likeycy.my;

import com.likeycy.my.sort.RadixSort1;
import com.likeycy.my.sort.cmp.Sort;
import com.likeycy.my.tools.Asserts;
import com.likeycy.my.tools.Integers;

import java.util.Arrays;

/**
 * @ClassName: TestSort
 * @Description: 排序测试
 * @Author: sodagreen
 * @Date: 2021/3/26 20:55
 * @Version: 1.0
 */
@SuppressWarnings({"rawtypes", "unchecked"})
public class TestSort {

    public static void main(String[] args) {
//        int[] array = {10, 9, 19, 28, 37, 64, 34, 6};


        /*Integer[] array1 = Integers.random(30000, 1, 50000);
        Integer[] array2 = Integers.copy(array1);
        Integer[] array3 = Integers.copy(array1);

        Times.test("HeapSort",() -> {
            new HeapSort().sort(array1);
        });

        Times.test("SelectionSort",() -> {
            new SelectionSort().sort(array2);
        });

        Times.test("BubbleSort2",() -> {
            new BubbleSort2().sort(array3);
        });*/

        /*Asserts.test(Integers.isAscOrder(array1));*/

        int[] intArray = {2, 4, 8, 8, 8, 12, 14};
        Asserts.test(BinarySearch.search(intArray, 5) == 2);
        Asserts.test(BinarySearch.search(intArray, 1) == 0);
        Asserts.test(BinarySearch.search(intArray, 15) == 7);
        Asserts.test(BinarySearch.search(intArray, 8) == 5);

        Integer[] array1 = Integers.random(150000, 1, 150000);
        Integer[] tempArray = {5, 7, 2, 4, 1, 13, 1};

        testSorts(tempArray
                /*, new BubbleSort()
                , new BubbleSort1()
                , new BubbleSort2()
                , new SelectionSort()
                , new InsertionSort1()
                , new InsertionSort2()
                , new InsertionSort3()
                , new HeapSort()
                , new MergeSort()
                , new QuickSort()
                , new ShellSort()
                , new CountingSort()
                , new RadixSort()*/
                , new RadixSort1()
                );

    }

    static void testSorts(Integer[] array, Sort... sorts) {
        for (Sort sort : sorts) {
            Integer[] newArray = Integers.copy(array);
            sort.sort(newArray);
            System.out.println(Arrays.toString(newArray));
        }

        Arrays.sort(sorts);

        for (Sort sort : sorts) {
            System.out.println(sort);
        }
    }

}
